package com.example.mobileyd203zwl0406;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


    private RadioGroup radioGroup;
    private RadioButton chexing1;
    private RadioButton chexing2;
    private RadioButton chexing3;
    private RadioButton chejian1;
    private RadioButton chejian2;
    private RadioButton chejian3;
    private RadioButton chejian4;
    private RadioGroup radioGroup2;
    private Button anniu1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                Log.i("车型", radioButton.getText().toString());
            }
        });

        radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                Log.i("车间",radioButton.getText().toString());
            }
        });

        anniu1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String msg = "";
                int carid = radioGroup.getCheckedRadioButtonId();
                if (carid != -1) {
                    msg = ((RadioButton) findViewById(carid)).getText().toString();
                }else {
                    msg= "未选车型";
                }
                Log.i("点击按钮",msg);

            }
        });


    }

    private void initView() {
        radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        chexing1 = (RadioButton) findViewById(R.id.chexing1);
        chexing2 = (RadioButton) findViewById(R.id.chexing2);
        chexing3 = (RadioButton) findViewById(R.id.chexing3);
        chejian1 = (RadioButton) findViewById(R.id.chejian1);
        chejian2 = (RadioButton) findViewById(R.id.chejian2);
        chejian3 = (RadioButton) findViewById(R.id.chejian3);
        chejian4 = (RadioButton) findViewById(R.id.chejian4);
        radioGroup2 = (RadioGroup) findViewById(R.id.radioGroup2);
        anniu1 = (Button) findViewById(R.id.anniu1);
    }
}